var Koa = require('koa'),

    render = require('koa-art-template'),

    router=require('koa-router')(),

    path=require('path'),

    bodyParser = require('koa-bodyparser'),

    admin = require('./router/admin.js'),

    static = require('koa-static'),

    cors = require('koa-cors'),

    index = require('./router/index.js'),

    koaJwt = require('koa-jwt');    
 
var app = new Koa();
app.use(bodyParser());

app.use(cors());

//配置静态web服务的中间件
app.use(static('./static'));
/*
  配置koa-art-template 模板引擎
*/
render(app,{
  root:path.join(__dirname, 'views'),
  extname:'.html',
  debug: process.env.NODE_ENA !== 'production'
})

//路由权限控制 除了path里的路径不需要验证token 其他都要
// app.use(
//   koaJwt({
//     secret: secret.sign
//   }).unless({
//     path: [/^\/login/, /^\/register/]
//   })
// );

router.use('/', index);

router.use('/admin',admin);



app.use(router.routes()).use(router.allowedMethods());
app.listen(3030);